package it.afs.worklog.application.form;

import java.util.List;

import it.afs.worklog.Attivita;

import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;

public class AttivitaDropDownChoice extends DropDownChoice<Attivita>
{
	private static final long serialVersionUID = -7229913257033720496L;
	
	private boolean showDisabled = false;

	public AttivitaDropDownChoice(String id, IModel<? extends List<? extends Attivita>> choices) {
		super(id, choices);
	}

	public AttivitaDropDownChoice(String id, IModel<Attivita> model, List<? extends Attivita> choices) {
		super(id, model, choices);
	}
	
	@Override
	protected void onConfigure()
	{
		setChoiceRenderer(new AttivitaChoiceRenderer());
		super.onConfigure();
	}
	
	@Override
	protected boolean isDisabled(Attivita object, int index, String selected)
	{
		return !object.getAttivo() && !showDisabled;
	}
	
	public boolean isShowDisabled() {
		return showDisabled;
	}

	public void setShowDisabled(boolean showDisabled) {
		this.showDisabled = showDisabled;
	}

	private class AttivitaChoiceRenderer implements IChoiceRenderer<Attivita>
	{
		private static final long serialVersionUID = -697801538673857862L;

		@Override
		public Object getDisplayValue(Attivita object) {
			return object.getOggetto();
		}

		@Override
		public String getIdValue(Attivita object, int index) {
			return String.valueOf(index);
		}
	}
}